package com.zhang.quartz;

import com.zhang.entity.response.ResponseResult;
import com.zhang.entity.vo.ExecuteCommandBody;
import com.zhang.service.client.QuartzClient;
import org.quartz.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.zhang.common.Constant.*;

/**
 * User: 张
 * Date: 2024-11-28
 * Time: 10:12
 * Description:
 */
@Component
public class MyJob implements Job {
    @Resource
    private QuartzClient quartzClient;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        ExecuteCommandBody executeCommandBody = new ExecuteCommandBody(
                (Integer) jobDataMap.get(SERVER_ID),
                (Integer) jobDataMap.get(SCRIPT_TEMPLATE_ID),
                (Integer) jobDataMap.get(EXECUTE_FREQUENCY)
        );
        ResponseResult<Object> result = quartzClient.executeCommand(executeCommandBody);
        // todo 记录本次执行
        System.out.println(result);
    }
}
